package com.learner.course.controller.admin;

import com.learner.course.service.CourseBaseService;
import com.learner.course.service.CourseCateService;
import com.learner.course.service.CourseDetailService;
import com.learner.course.service.CourseMarketService;
import com.learner.course.service.CoursePlanService;
import com.learner.course.service.CourseService;
import com.learner.pojo.course.Category;
import com.learner.pojo.course.CourseDetail;
import com.learner.pojo.course.CourseMarket;
import com.learner.pojo.course.CoursePlan;
import com.learner.pojo.course.expand.CategoryNode;
import com.learner.pojo.course.expand.CoursePlanNode;
import com.learner.pojo.course.expand.CourseQueryVo;
import com.learner.pojo.course.expand.CourseView;
import com.learner.pojo.page.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author ice2020x
 * @Description: 课程管理
 */
@RestController
@RequestMapping("/admin/edu/course")
@Slf4j
public class CourseController {

    @Autowired
    CoursePlanService coursePlanService;

    @Autowired
    CourseService courseService;

    @Autowired
    CourseCateService courseCateService;

    @Autowired
    CourseBaseService courseBaseService;

    @Autowired
    CourseMarketService courseMarketService;


    @Autowired
    private CourseDetailService detailService;

    /**
     * 保存课程的概述信息
     *
     * @param courseDetail 详细描述
     */
    @PostMapping("/detail/save")
    public void save(@RequestBody CourseDetail courseDetail) {
        detailService.save(courseDetail);
    }

    /**
     * 获取课程的概述信息
     *
     * @param courseId 课程id
     * @return 结果
     */
    @GetMapping("/detail/get/{courseId}")
    public List<Map<String, String>> getCourseDetailByCourseId(@PathVariable("courseId") String courseId) {
        return detailService.getCourseDetailByCourseId(courseId);
    }

    /**
     * 保存课程分类
     *
     * @param category 分类信息
     * @return 结果
     */
    @PostMapping("/course_cate")
    public Category addCourseCategory(@RequestBody Category category) {
        return courseCateService.saveCate(category);
    }


    /**
     * 查询课程计划的接口
     *
     * @param courseId 课程计划
     * @return 结果
     */
    @GetMapping("/course_plan_id/{courseId}")
    public CoursePlan getCoursePlanIdByCourseId(@PathVariable("courseId") String courseId) {
        return coursePlanService.getCoursePlanIdByCourseId(courseId);
    }

    /**
     * 根据条件查询课程视图列表
     *
     * @param courseQueryVo 参数
     * @return 结果
     */
    @PostMapping("/course_view/findAll/condition")
    public PageResult<CourseView> listPage(@RequestBody CourseQueryVo courseQueryVo) {
        System.out.println(courseQueryVo);
        log.info("根据条件查询课程视图列表，参数:{}",courseQueryVo);
        return courseService.findAllByCondition(courseQueryVo);
    }


    /**
     * 查询课程计划的接口
     *
     * @param courseId 课程id
     * @return 结果
     */
    @GetMapping("/course_plan/list/{courseId}")
    public CoursePlanNode findCoursePlanList(@PathVariable("courseId") String courseId) {
        return coursePlanService.findCoursePlanListByCourseId(courseId);
    }

    /**
     * 添加课程计划
     *
     * @param coursePlan 课程id
     * @return 结果
     */
    @PostMapping("/course_plan/add")
    public CoursePlan addCoursePlan(@RequestBody CoursePlan coursePlan) {
        return coursePlanService.addCoursePlan(coursePlan);
    }


    /**
     * 查询课程的分类
     *
     * @return 结果
     */
    @GetMapping("/course_cate/list")
    public CategoryNode selectCateList() {
        return courseCateService.selectCateList();
    }


    /**
     * @Description: 根据id查看课程营销
     * @Author: ice2020x
     * @Date: 2021/7/27
     */
    @GetMapping("/course_market/get/{id}")
    public CourseMarket getCourseMarketById(@PathVariable("id") String courseId) {
        return courseMarketService.getCourseMarketById(courseId);
    }

    /**
     * 根据id修改课程营销
     *
     * @param id           课程id
     * @param courseMarket 课程营销信息
     * @return 结果
     */
    @PutMapping("/course_market/update/{id}")
    public CourseMarket updateCourseMarket(@PathVariable("id") String id, @RequestBody CourseMarket courseMarket) {
        return courseMarketService.updateCourseMarket(id, courseMarket);
    }


    /**
     * 课程视图，包括课程的全部信息（基础信息，课程计划，课程营销，图片等）
     *
     * @param id 课程id
     * @return 结果
     */
    @GetMapping("/course_view/get/{id}")
    public CourseView courseView(@PathVariable("id") String id) {
        return courseService.courseView(id);
    }


    /**
     * 课程发布（如果课程视图预览的信息没什么问题，则点击发布）
     *
     * @param id 课程id
     */
    @GetMapping("/course_view/publish/{id}")
    public void publicCourse(@PathVariable("id") String id) {
         courseService.publicCourse(id);
    }


}
